package com.itcast.service.product.impl;

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.itcast.bean.product.ProductType;
import com.itcast.dao.BaseDao;
import com.itcast.dao.impl.ProductDao;
import com.itcast.service.product.ProductTypeService;
import com.itcast.util.Dao.OrderBy;
import com.itcast.util.Dao.PredicateDate;
import com.itcast.util.Dao.PredicateType;

@Service
@Transactional
public class ProductTypeServiceBean implements ProductTypeService {

	BaseDao<ProductType, Integer> productDao;

	public BaseDao<ProductType, Integer> getProductDao() {
		return productDao;
	}

	@Resource(name = "productDao")
	public void setProductDao(BaseDao<ProductType, Integer> productDao) {
		this.productDao = productDao;
	}

	@Override
	public void save(ProductType productType) {
		productDao.add(productType);
	}

	@Override
	public void delete(int productTypeId) {
		productDao.deleteById(productTypeId);
	}

	@Override
	public List<ProductType> findList(int firstResult, int maxResults) {
		return productDao.findList(firstResult, maxResults);
	}
	
	@Override
	public List<ProductType> findListForWhere(int parentId, int firstResult, int maxResults) {
		LinkedHashMap<PredicateDate, PredicateType> Predicates = new LinkedHashMap<PredicateDate, PredicateType>();
		Predicates.put(new PredicateDate("parentType", new ProductType(parentId)), PredicateType.EQUAL);
		return productDao.findListForWhere(Predicates, firstResult, maxResults);
	}

	public int findList(
			LinkedHashMap<PredicateDate, PredicateType> Predicates,
			int firstResult,
			int maxResults) {

		return productDao.findList(Predicates, firstResult, maxResults);

	}

}
